package com.cskaoyan.service;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.IndexVo;

import com.cskaoyan.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WxIndexServiceImpl implements WxIndexService {
    @Autowired
    MarketAdMapper marketAdMapper;
    @Autowired
    MarketBrandMapper marketBrandMapper;
    @Autowired
    MarketCategoryMapper marketCategoryMapper;
    @Autowired
    MarketCouponMapper marketCouponMapper;
    @Autowired
    MarketGoodsMapper marketGoodsMapper;
    @Autowired
    MarketTopicMapper marketTopicMapper;
    @Override
    public IndexVo list() {
        IndexVo indexVo = new IndexVo();
        MarketAdExample example = new MarketAdExample();
        MarketAdExample.Criteria criteria = example.createCriteria();
        List<MarketAd> marketAds = marketAdMapper.selectByExample(example);
        indexVo.setBanner(marketAds);

        MarketBrandExample example1 = new MarketBrandExample();
        MarketBrandExample.Criteria criteria1 = example1.createCriteria();
        List<MarketBrand> marketBrands = marketBrandMapper.selectByExample(example1);
        indexVo.setBrandList(marketBrands);

        MarketCategoryExample example2 = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria2 = example2.createCriteria();
        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(example2);
        indexVo.setChannel(marketCategories);

        //优惠券
        MarketCouponExample example3 = new MarketCouponExample();
        MarketCouponExample.Criteria criteria3 = example3.createCriteria();
        List<MarketCoupon> marketCoupons = marketCouponMapper.selectByExample(example3);
        indexVo.setCouponList(marketCoupons);


        //底层商品
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        marketCategoryExample.createCriteria().andPidEqualTo(0);
        //获得一级目录
        List<MarketCategory> fMarketCategories = marketCategoryMapper.selectByExample(marketCategoryExample);

        for (MarketCategory marketCategory : fMarketCategories) {
            marketCategoryExample.clear();
            marketCategoryExample.createCriteria().andPidEqualTo(marketCategory.getId());
            List<MarketCategory> marketCategories1 = marketCategoryMapper.selectByExample(marketCategoryExample);
            marketCategory.setChildren(marketCategories1);
        }






        //热门商品
        MarketGoodsExample example5 = new MarketGoodsExample();
        MarketGoodsExample.Criteria criteria5 = example5.createCriteria();
        criteria5.andIsHotEqualTo(true);
        List<MarketGoods> marketGoods = marketGoodsMapper.selectByExample(example5);
        indexVo.setHotGoodsList(marketGoods);

        //新商品
        MarketGoodsExample example6 = new MarketGoodsExample();
        MarketGoodsExample.Criteria criteria6 = example6.createCriteria();
        criteria6.andIsNewEqualTo(true);
        List<MarketGoods> marketGoods1 = marketGoodsMapper.selectByExample(example6);
        indexVo.setNewGoodsList(marketGoods1);

        //专题
        MarketTopicExample example7 = new MarketTopicExample();
        MarketTopicExample.Criteria criteria7 = example7.createCriteria();
        List<MarketTopic> marketTopics = marketTopicMapper.selectByExample(example7);
        indexVo.setTopicList(marketTopics);




        return indexVo;
    }
}
